<!--
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-03 14:41:20
 * @LastEditTime: 2022-08-26 13:55:19
 * @LastEditors: CHINAKAIYUAN
 * @Description:   :gridOps="gridOptions" 
-->
<template>
	<sc-VxeTable
		ref="xGrid1"
		:tablecode="'system_api'"
		:gridEvts="gridEvents"
		:url="this.$API.system.api.list"
	>
	</sc-VxeTable>

	<save-dialog
		v-if="dialog.save"
		ref="saveDialog"
		@success="handleSuccess"
		@closed="dialog.save = false"
	></save-dialog>
</template>

<script>
// import { ref } from "vue";
import SaveDialog from "./save";
export default {
	name: "client",
	components: {
		SaveDialog,
	},
	data() {
		return {
			dialog: {
				save: false,
			},
			gridOptions: {},
			gridEvents: {},
		};
	},
	created() {
		this.gridEvents = {
			cellDblclick: ({ row }) => {
				this.edit(row);
			},
			add: ({ code }) => {
				this.openSave(code);
			},
			edit: () => {
				let selects = this.$refs.xGrid1.xGrid.getCheckboxRecords();
				console.log(selects);
				if (selects.length == 0) {
					this.$message.error("必须选中元素");
					return;
				}
				this.edit(selects[0]);
			},
		};
	},
	methods: {
		openSave() {
			this.dialog.save = true;
			this.$nextTick(() => {
				this.$refs.saveDialog.open();
			});
		},
		handleSuccess() {
			this.$refs.xGrid1.refresh();
		},
		edit(item) {
			let selected = {};
			this.dialog.save = true;

			// this.openSave();
			if (typeof item == "undefined") {
				selected = this.$refs.xGrid1.xGrid.getCheckboxRecords()[0];
			} else selected = item;

			this.$nextTick(() => {
				this.$refs.saveDialog.open("edit").setData(selected);
			});
		},
	},
};
</script>
